package com.encapi.samples.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.encapi.framework.wrapper.response.AbstractResponseDataWrapper;
import com.encapi.samples.response.ResultResponse;
import org.springframework.stereotype.Component;

@Component
public class MyFastjsonResponseDataWrapper extends AbstractResponseDataWrapper<ResultResponse> {

    @Override
    protected String convertJson(Object needEncData) throws Exception {
        return JSON.toJSONString(needEncData,
                SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteDateUseDateFormat,
                SerializerFeature.WriteNullNumberAsZero,
                SerializerFeature.WriteNullBooleanAsFalse,
                SerializerFeature.WriteNullListAsEmpty);
    }

    @Override
    protected Object parseOriginData(ResultResponse originData) {
        return originData.getData();
    }

    @Override
    protected ResultResponse wrapToEntity(ResultResponse originData, String encryptedData) {
        // 重新赋值
        originData.setData(encryptedData);
        return originData;
    }

}
